package com.hiwhitley.easy.day26;

import java.util.HashSet;

/**
 * Created by hiwhitley on 2016/10/25.
 */
public class FirstMissingPositive_41 {
    public int firstMissingPositive(int[] nums) {
        HashSet<Integer> set = new HashSet<Integer>();
        int length = nums.length;
        if (length <= 0)
            return 1;

        for (int i = 0; i < length; i++) {
            set.add(nums[i]);
        }

        int index = 1;
        while (set.contains(index++)) ;
        return index - 1;
    }

    public static void main(String[] args) {
        FirstMissingPositive_41 main = new FirstMissingPositive_41();
        System.out.println(main.firstMissingPositive(new int[]{1, 2, 0}));
    }
}
